package online.mjchow.fic.util;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by mjchow on 16-10-30.
 */
public enum ApiStatus {

    SUCCESS(0, "Success"),

    USERNAME_OR_PASSWORD_ERROR(10000, "账号或密码错误"),


    PARAM_DATA_ERROR(100, "Invalid parameter value"),
    INTERNAL_SERVER_ERROR(500, "Internal server error"),

    //new status
    FORMAT_INVALID(30001, "格式错误"),
    DATA_NOT_FOUND(30002, "数据不存在"),
    DATA_EXISTED(30003, "数据已存在"),
    DATA_INVALID(30004, "数据无效"),
    LOGIN_REQUIRED(30005, "登入错误"),
    NOT_LOGIN(30006, "NOT_LOGIN");

    private static final Map<Integer, ApiStatus> map = new HashMap<>();

    static {
        for(ApiStatus apiStatus: ApiStatus.values()) {
            map.put(apiStatus.getCode(), apiStatus);
        }
    }

    private int code;
    private String desc;

    ApiStatus(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public int getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public static ApiStatus getApiStatus(int code) {
        return map.get(code);
    }
}
